home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagd_f.zip / DRIVES.SWG / 0069_Network Drives.pas < prev    next >
Pascal/Delphi Source File  |  1994-02-03  |  4KB  |  90 lines

  1. {
  2.   >Hi, I'm interested in trying to identify what type of drive a
  3.   >logical drive is (specifically, whether or not a hard drive is
  4.   >a network drive; I want the installation program I'm writing
  5.   >to prevent the user from installing to a network drive).
  6.  
  7.  Hi Jim,
  8.  
  9.  I don't have access to a network, but the following code will
  10.  consistently assure me that my drives are all local ;) ... }
  11.  
  12. (************************* NETDRV.PAS ******************************)
  13. PROGRAM NetDrive;                     { compiler: Turbo Pascal 4.0+ }
  14.                                       { Jan.17.94 Greg Vigneault    }
  15.  
  16. USES  Dos;                            { import MsDos, Registers     }
  17.  
  18. CONST Beep          = CHR(7);         { ASCII bell-tone             }
  19.  
  20. VAR   Reg           : Registers;      { to use CPU registers        }
  21.       DosErrorCode  : WORD;           { MsDos function error code   }
  22.       DriveID       : String[1];      { for PC/AT drive 'A'..'Z'    }
  23.       DriveIsRemote : BOOLEAN;        { TRUE or FALSE, of course    }
  24.  
  25. (*-----------------------------------------------------------------*)
  26. (* Return PC/MS-DOS version, times 100 (eg. 310 = version 3.1) ... *)
  27.  
  28. FUNCTION DosVersion : WORD;
  29.   BEGIN
  30.     Reg.AX := $3000;                  { Dos fn: get Dos version   }
  31.     MsDos (Reg);                      { call the Dos services     }
  32.     DosVersion := WORD(Reg.AL) * 100 + WORD(Reg.AH);  { convert   }
  33.   END {DosVersion};
  34.  
  35. (*-----------------------------------------------------------------*)
  36. (*  Return TRUE if Drive is redirected to a network server...      *)
  37.  
  38. FUNCTION NetworkDrive (Drive:CHAR):BOOLEAN;
  39.   BEGIN
  40.     Drive := UpCase (Drive);            { Drive _must_ be 'A'..'Z'  }
  41.     IF (Drive IN ['A'..'Z']) THEN BEGIN { make sure of 'A'..'Z'     }
  42.       Reg.BL := ORD(Drive) - 64;      { 1 = A:, 2 = B:, 3 = C: etc. }
  43.       Reg.AX := $4409;                { Dos fn: check if dev remote }
  44.       MsDos (Reg);                    { call Dos' services          }
  45.       IF ODD(Reg.FLAGS) THEN          { Dos reports function error? }
  46.         DosErrorCode := Reg.AX        { yes: return Dos' error code }
  47.       ELSE BEGIN                      {   else ...                  }
  48.         DosErrorCode := 0;            { 0 = no error was detected   }
  49.         IF ODD(Reg.DX SHR 12) THEN    { is Drive remote?            }
  50.           NetworkDrive := TRUE        { yes: return TRUE            }
  51.         ELSE
  52.           NetworkDrive := FALSE;      { no: return FALSE            }
  53.         {END IF ODD(Reg.DX...}
  54.       END; {IF ODD(Reg.FLAGS)}
  55.     END; {IF Drive}
  56.   END {NetworkDrive};
  57.  
  58. (*-----------------------------------------------------------------*)
  59. BEGIN {NetDrive}
  60.  
  61.   WriteLn;
  62.  
  63.   IF (ParamCount <> 1) THEN BEGIN                 { user input?     }
  64.     WriteLn ('Usage: NETDRV <DriveLetter>',Beep); { no: offer hint  }
  65.     HALT (1);                                     { abort program   }
  66.   END;
  67.  
  68.   IF (DosVersion < 310) THEN BEGIN                { check DOS ver   }
  69.     WriteLn ('DOS version 3.1+ is needed.',Beep); { version too low }
  70.     HALT (2);                                     { abort program   }
  71.   END;
  72.  
  73.   DriveID := ParamStr(1);                       { get user's input  }
  74.   DriveID[1] := UpCase (DriveID[1]);            { to uppercase      }
  75.   DriveIsRemote := NetWorkDrive (DriveID[1]);   { check per netwrok }
  76.  
  77.   { _ALWAYS_ check if the function call failed....................  }
  78.  
  79.   IF (DosErrorCode <> 0) THEN BEGIN             { any DOS errors?   }
  80.     WriteLn ('!DOS error #',DosErrorCode,Beep); { DOS fn failed     }
  81.     HALT (3);                                   { abort program     }
  82.   END;
  83.  
  84.   Write ('Drive ',DriveID[1],': is ');          { inform user of    }
  85.   IF NOT DriveIsRemote THEN Write ('NOT ');     {  the drive status }
  86.   WriteLn ('redirected to a network.');
  87.  
  88. END {NetDrive}.
  89. (*******************************************************************)
  90.